/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controldepuntos.pantallas;

import controldepuntos.clases.AdministradorVentanas;
import controldepuntos.clases.TrAlumno;
import controldepuntos.clases.TrIncidente;
import controldepuntos.clases.Utilidades;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author DIANA
 */
public class ACHistorialAlumno extends javax.swing.JFrame {
    private static Integer puntosPorIncidencias=0;
    private static Integer puntosRestantes=0;
    /**
     * Creates new form ReporteUsuario
     */
    public ACHistorialAlumno() {
        initComponents();
        cargarIncidentesAlumno();
        cargarDatosAlumno();
    }
    
    public void cargarDatosAlumno(){
         //JOptionPane.showMessageDialog(AdministradorVentanas.pantallaModificarIncidencia, Utilidades.idAlumno);
         try{
            TrAlumno alumno = new TrAlumno();
            alumno=alumno.seleccionarPorNumeroDeControl(Utilidades.numeroDeControl.toString());
            if(alumno!=null){
               lblNombreCompleto.setText(alumno.getNombre()+" "+alumno.getApPaterno()+" "+alumno.getApMaterno());
               lblGrado.setText(String.valueOf(alumno.getGrado()));
               lblGrupo.setText(String.valueOf(alumno.getGrupo()));
            }
         }catch(Exception ex){
             JOptionPane.showMessageDialog(AdministradorVentanas.pantallaHistorialAlumno, "Lo sentimos, Ocurrió un error hola. "+ex.getMessage(),"Error",JOptionPane.ERROR_MESSAGE);
         }
     }
    public void cargarIncidentesAlumno(){
        try{
            //Resetear valores de puntos para que no se sumen con los anteriores
            puntosPorIncidencias=0;
            puntosRestantes=0;
            DefaultTableModel model = new DefaultTableModel(){ 
            public boolean isCellEditable(int rowIndex,int columnIndex){return false;} };
            TrIncidente trIncidente = new TrIncidente();
            ResultSet rs = trIncidente.buscarTodoPorNumeroDeControlResultSet(Utilidades.numeroDeControl.toString());
            ResultSetMetaData rsmd = rs.getMetaData();
            int numeroDeColumnas = rsmd.getColumnCount();
            for(int i=1;i<=numeroDeColumnas;i++){
                model.addColumn(rsmd.getColumnLabel(i));
            }
            while(rs.next()){
                Object[] fila = new Object[numeroDeColumnas];
                puntosPorIncidencias=puntosPorIncidencias+rs.getInt("puntos");
               for(int i=0;i<numeroDeColumnas;i++){
                   fila[i]=rs.getObject(i+1);
               }
               model.addRow(fila);
            }
            tblIncidentes.setModel(model);
            lblPuntosPorIncidentes.setText(puntosPorIncidencias.toString());
            puntosRestantes=100-puntosPorIncidencias;
            lblPuntosRestantes.setText(puntosRestantes.toString());
            //Ocultar fila Id
            tblIncidentes.getColumnModel().getColumn(0).setMaxWidth(0);
            tblIncidentes.getColumnModel().getColumn(0).setMinWidth(0);
            tblIncidentes.getTableHeader().getColumnModel().getColumn(0).setMinWidth(0);
            tblIncidentes.getTableHeader().getColumnModel().getColumn(0).setMaxWidth(0);
            
        }catch(Exception ex){
            JOptionPane.showMessageDialog(AdministradorVentanas.pantallaHistorialAlumno, "Los sentimos. Ocurrió un error hola."+ex.getMessage(),"Error",JOptionPane.ERROR_MESSAGE);
        }
        
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblIncidentes = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        lblNombreCompleto = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        lblPuntosPorIncidentes = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        lblPuntosRestantes = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        lblGrado = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        lblGrupo = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        jPanel1.setBackground(new java.awt.Color(204, 204, 204));

        tblIncidentes.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        tblIncidentes.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblIncidentes.setName("tblHistorial"); // NOI18N
        jScrollPane1.setViewportView(tblIncidentes);

        jButton1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/controldepuntos/recursos/inicio.JPG"))); // NOI18N
        jButton1.setText("Inicio");
        jButton1.setName("btnSalir"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 36)); // NOI18N
        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/controldepuntos/recursos/alumno.jpg"))); // NOI18N
        jLabel1.setText("Historial");
        jLabel1.setName("lblHistorial"); // NOI18N

        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/controldepuntos/recursos/LogoSIAPPSuperChico.jpg"))); // NOI18N

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel2.setText("Nombre del alumno:");

        lblNombreCompleto.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        lblNombreCompleto.setText("jLabel4");

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel4.setText("Puntos por incidentes:");

        lblPuntosPorIncidentes.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        lblPuntosPorIncidentes.setForeground(new java.awt.Color(255, 0, 0));
        lblPuntosPorIncidentes.setText("jLabel5");

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel5.setText("Puntos restantes:");

        lblPuntosRestantes.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        lblPuntosRestantes.setForeground(new java.awt.Color(255, 0, 0));
        lblPuntosRestantes.setText("jLabel6");

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel6.setText("Grado:");

        lblGrado.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        lblGrado.setText("jLabel7");

        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel7.setText("Grupo:");

        lblGrupo.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        lblGrupo.setText("jLabel8");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 519, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(jButton1))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(43, 43, 43)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel6)
                                    .addComponent(jLabel7))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(lblGrupo)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jLabel5))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(lblGrado)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jLabel4))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(lblNombreCompleto)
                                        .addGap(0, 0, Short.MAX_VALUE))))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel1)
                                .addGap(95, 95, 95)))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(67, 67, 67)
                                .addComponent(jLabel3))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lblPuntosRestantes)
                                    .addComponent(lblPuntosPorIncidentes))))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(30, 30, 30)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(lblNombreCompleto))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblPuntosPorIncidentes)
                            .addComponent(jLabel4)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(14, 14, 14)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(lblGrado))))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addComponent(lblPuntosRestantes))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 36, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addComponent(jButton1)
                                .addContainerGap())
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(28, 28, 28))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(lblGrupo))
                        .addGap(0, 0, Short.MAX_VALUE))))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        AdministradorVentanas.ocultarPantallaHistorialAlumno();
        AdministradorVentanas.mostrarPantallaInicio();
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ACHistorialAlumno.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ACHistorialAlumno.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ACHistorialAlumno.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ACHistorialAlumno.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ACHistorialAlumno().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblGrado;
    private javax.swing.JLabel lblGrupo;
    private javax.swing.JLabel lblNombreCompleto;
    private javax.swing.JLabel lblPuntosPorIncidentes;
    private javax.swing.JLabel lblPuntosRestantes;
    private javax.swing.JTable tblIncidentes;
    // End of variables declaration//GEN-END:variables
}
